package mysql

import (
	"gorm.io/gorm"
	"shopping/logger"
	"shopping/model"
)

type OrderItemDao struct {
	db *gorm.DB
}

// NewOrderItemDao 实例化
func NewOrderItemDao(db *gorm.DB) *OrderItemDao {
	return &OrderItemDao{
		db: db,
	}
}

// Migration 创建表
func (dao *OrderItemDao) Migration() {
	err := dao.db.AutoMigrate(&model.OrderedItem{})
	if err != nil {
		logger.Log.Error(err.Error())
	}
}

// Update 更新
func (dao *OrderItemDao) Update(item model.OrderedItem) error {
	return dao.db.Save(&item).Error
}

// Create 创建订单item
func (dao *OrderItemDao) Create(ci *model.OrderedItem) error {
	return dao.db.Create(ci).Error
}
